<template>
	<el-dialog :model-value="visible" width="40%" :z-index="9" @close="cancel">
		<template #header>
			<div class="custom-header">回复</div>
		</template>

		<div class="boardBox">
			<el-form ref="queryFormRef" label-width="90px" style="width: 100%" :model="queryParams" :rules="rules">
				<el-form-item label="标准名称" prop="standardName">
					<el-input v-model="queryParams.standardName" disabled placeholder="标准名称" clearable />
				</el-form-item>
				<el-form-item disabled label="咨询人" prop="consultant">
					<el-input v-model="queryParams.consultant" disabled placeholder="咨询人" clearable />
				</el-form-item>

				<el-form-item label="咨询日期">
					<el-input v-model="queryParams.consultDate" disabled placeholder="咨询日期" clearable />
				</el-form-item>
				<el-form-item label="联系地址">
					<el-input v-model="queryParams.contactAddress" disabled placeholder="联系地址" clearable />
				</el-form-item>

				<el-form-item label="联系电话">
					<el-input v-model="queryParams.contactTel" disabled placeholder="联系电话" clearable />
				</el-form-item>
				<el-form-item label="电子邮件">
					<el-input v-model="queryParams.contactEmail" disabled placeholder="电子邮件" clearable />
				</el-form-item>
				<el-form-item label="是否公开">
					<el-select v-model="queryParams.hasPublic" size="large" :disabled="isgettrue">
						<el-option v-for="item in gklist" :key="item.value" :label="item.name" :value="item.value" />
					</el-select>
				</el-form-item>
				<el-form-item label="咨询内容">
					<el-input v-model="queryParams.consultContent" disabled placeholder="咨询内容" clearable type="textarea" :rows="5" />
				</el-form-item>
				<el-form-item label="咨询回复">
					<el-input v-model="queryParams.replyContent" placeholder="咨询回复" clearable type="textarea" maxlength="300" show-word-limit :rows="5" />
				</el-form-item>
			</el-form>
			<div class="dialog-footer">
				<el-button type="primary" @click="onSubmit">提交</el-button>
				<el-button @click="cancel">关闭</el-button>
			</div>
		</div>

		<!-- <Invitesuccess v-model:visible="addvisible" :info="info" /> -->
	</el-dialog>
</template>
<script setup lang="ts">
import { ElMessage, FormInstance } from 'element-plus'
import { reactive, ref, computed } from 'vue'
import { useUserStore } from '@/store/modules/user'
import { consultReplyApi, consultReplyDetailApi } from '@/api/standardapplication/index'

const props = defineProps({
	visible: {
		type: Boolean,
		default: false
	}
})
// 是否公开 0：公开  1：未公开
const gklist = [
	{ name: '全部', value: ' ' },
	{ name: '公开', value: 0 },
	{ name: '不公开', value: 1 }
]

const update = ref(false)
const queryFormRef = ref<FormInstance>()

const queryParams = ref({
	id: '',
	standardName: '',
	projectInfoId: '',
	consultant: '',
	contactAddress: '',
	contactTel: '',
	contactEmail: '',
	consultContent: '',
	consultDate: '',
	hasPublic: '',
	hasNoticed: '',
	replyContent: '',
	replyDate: '',
	replyPerson: '',
	consultStatus: '',
	publishStatus: ''
})
const rules = reactive({
	name: [{ required: true, message: '请输入员工姓名', trigger: 'blur' }],
	hired_time: [{ required: true, message: '请选择入职时间', trigger: 'change' }],
	dept_id: [{ required: true, message: '请选择部门', trigger: 'change' }],
	position: [{ required: true, message: '请输入岗位', trigger: 'blur' }],
	mobile: [{ required: true, message: '请输入手机号码', trigger: 'blur' }],
	job_status: [{ required: true, message: '请选择员工状态', trigger: 'change' }]
})
const emit = defineEmits<{ (event: 'update:visible', value: boolean): void; (event: 'refreshDataList', value: boolean): void }>()
const userStore = useUserStore()
const isgettrue = computed(() => {
	if (userStore.user.roleCode.includes('ZZADMIN') || userStore.user.roleCode.includes('SHZZ') || userStore.user.roleCode.includes('SYADMIN')) {
		return false
	} else {
		return true
	}
})
// true新增  、false编辑
const init = (isUpdate: boolean, row: any) => {
	getDetail(row)
}

const getDetail = async (row: any) => {
	let params = {
		id: row
	}
	await consultReplyDetailApi(params).then(res => {
		Object.assign(queryParams.value, res.data)
		console.log(res.data)
	})
}
const cancel = () => {
	emit('update:visible', false)
	emit('refreshDataList')
}
const onSubmit = async () => {
	if (queryParams.value.replyContent == '') {
		ElMessage({
			type: 'warning',
			message: '请输入回复内容'
		})
		return
	}
	let params = {
		id: queryParams.value.id,
		replyContent: queryParams.value.replyContent
	}
	await consultReplyApi(params).then(res => {
		// console.log(res.data)
		ElMessage({
			type: 'success',
			message: '操作成功'
		})
		cancel()
	})
}
defineExpose({
	init
})
</script>

<style lang="scss" scoped>
.boardBox {
	display: flex;
	align-items: center;
	flex-direction: column;
	flex-wrap: wrap;
	justify-content: space-around;
	overflow-y: scroll;
	height: 100%;

	&::-webkit-scrollbar {
		display: none;
	}

	-ms-overflow-style: none;
	scrollbar-width: none;

	.tishi {
		font-size: 14px;
		color: #999;
		background-color: #f3f8fb;
		padding: 5px 10px;
		border-radius: 6px;
	}
}
</style>
